package Extended;

import java.awt.*;
import java.io.*;
import java.util.regex.*;


public class SimpleTool
{
	public static String BaseName(String Path)
	{
		return new File(Path).getName();
	}

	public static int StringToInteger(String Old)
	{
		return Integer.parseInt(Old);
	}

	public static boolean StringToBoolean(String Old)
	{
		return Boolean.parseBoolean(Old);
	}

	public static Color StringToColor(String Old)
	{
		final int Space1 = Old.indexOf(" ");
		final int Space2 = Old.indexOf(" ", Space1 + 1);
		final int Space3 = Old.indexOf(" ", Space2 + 1);
		final int R = StringToInteger(Old.substring(0, Space1));
		final int G = StringToInteger(Old.substring(Space1 + 1, Space2));
		final int B = StringToInteger(Old.substring(Space2 + 1, Space3));
		final int Alpha = StringToInteger(Old.substring(Space3 + 1, Old.length()));
		return new Color(R, G, B, Alpha);
	}

	public static String ColorToString(Color Old)
	{
		return Old.getRed() + " " + Old.getGreen() + " " + Old.getBlue() + " " + Old.getAlpha();
	}

	public static boolean IsNumber(String Text)
	{
		return Pattern.compile("[0-9]*").matcher(Text).matches();
	}

	public static int StringCount(String Text, String Find)
	{
		int c = 0;
		int p = 0;

		while(Text.indexOf(Find, p) != -1)
		{
			c ++;
			p = Text.indexOf(Find, p) + 1;
		}

		return c;
	}
}
